define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    let pid = $('#pid').val();
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coursechaptersection/index' + location.search,
                    add_url: 'coursechaptersection/add/pid/'+pid,
                    edit_url: 'coursechaptersection/edit',
                    //del_url: 'coursechaptersection/del',
                    multi_url: 'coursechaptersection/multi',
                    import_url: 'coursechaptersection/import',
                    table: 'course_chapter_section',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'sort',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('小节编号')},
                        {
                            field: 'pid',
                            title: __('大章编号'),
                            visible: false
                        },
                        {field: 'name', title: __('小节名称'), operate: 'LIKE'},
                        {field: 'other_id', title: __('第三方编号')},
                        {
                            field: 'status',
                            title: __('状态'),
                            formatter: Table.api.formatter.status,
                            searchList: {1: __('Normal'), 2: __('Hidden')}
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons:[
                                {
                                    name: 'detail',
                                    text: '题目管理',
                                    title: '题目管理',
                                    icon: 'fa fa-question-circle',
                                    classname: 'btn btn-xs btn-primary btn-addtabs',
                                    url: function (row) {
                                        return 'question/index/extend_id/'+row.id;
                                    },
                                },
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
